
/**
 * 请求模块
 */
define(["jquery","core"],function($,core)
{
	var simplePost=function(url,args,callback)
	{
		callback=core.util.defaultValue(callback,function(){});
		args.token=core.token.get();
		core.util.simplePost(core.api.getApi(url),$.param(args,true),callback);
	};
	
	var simpleGet=function(url,args,callback)
	{
		callback=core.util.defaultValue(callback,function(){});
		args.token=core.token.get();
		core.util.simpleGet(core.api.getApi(url),$.param(args,true),callback);
	};
	
	var request={};
	
	request.util=
	{
		simplePost:simplePost,
		simpleGet:simpleGet
	};
	
	//软件
	request.software=
	{
		//搜索
		search:function(keyword,callback)
		{
			simpleGet("/software/search",{keyword:keyword},callback);
		},
		//根据ID返回
		findById:function(id,callback)
		{
			simpleGet("/software/"+id,{},callback);
		},
		//返回首页推荐
		findByRecommendIndex:function(callback)
		{
			simpleGet("/software/recommend/index",{},callback);
		},
		//返回推荐
		findByRecommend:function(pn,callback)
		{
			simpleGet("/software/recommend",{pn:pn},callback);
		},
		//创建
		create:function(name,home_page,doc_url,download_url,introduce,callback)
		{
			simplePost("/software/create",{name:name,home_page:home_page,doc_url:doc_url,download_url:download_url,introduce:introduce},callback);
		},
		//设置推荐
		setRecommend:function(id,callback)
		{
			simplePost("/software/setRecommend/"+id,{},callback);
		},
		//编辑
		edit:function(id,name,home_page,doc_url,download_url,introduce,callback)
		{
			simplePost("/software/edit/"+id,{name:name,home_page:home_page,doc_url:doc_url,download_url:download_url,introduce:introduce},callback);
		},
		favorite:
		{
			//关注
			create:function(id,callback)
			{
				simplePost("/software/favorite/create",{id:id},callback);
			},
			//删除关注
			remove:function(id,callback)
			{
				simplePost("/software/favorite/delete",{id:id},callback);
			}
		}
	};
	
	//用户
	request.user=
	{
		//编辑
		edit:function(headphoto,username,signature,callback)
		{
			simplePost("/user/edit",{headphoto:headphoto,username:username,signature:signature},callback);
		},
		//登录
		login:function(account,password,callback)
		{
			simplePost("/user/login",{account:account,password:password},callback);
		},
		//注册
		register:function(account,password,callback)
		{
			simplePost("/user/register",{account:account,password:password},callback);
		},
		//登出
		logout:function(callback)
		{
			simplePost("/user/logout",{},callback);
		},
		//返回信息
		getMessageByToken:function(callback)
		{
			simpleGet("/user/message/token",{},callback);
		},
		//根据ID返回信息
		getMessageById:function(id,callback)
		{
			simpleGet("/user/message/"+id,{},callback);
		},
		//用户首页数据
		home:function(id,callback)
		{
			simpleGet("/user/home/"+id,{},callback);
		},
		//修改密码
		updatePassword:function(oldPassword,newPassword,callback)
		{
			simplePost("/user/password/update",{oldPassword:oldPassword,newPassword:newPassword},callback);	
		},
		//注册认证
		registerCheck:function(identity,callback)
		{
			simplePost("/user/register/check",{identity:identity},callback);	
		},
		bar:
		{
			//返回
			find:function(callback)
			{
				simpleGet("/user/bar/token",{},callback);
			}
		},
		menu:
		{
			//返回
			find:function(callback)
			{
				simpleGet("/user/menu/token",{},callback);
			}
		},
		follow:
		{
			//关注
			create:function(target,callback)
			{
				simplePost("/user/follow/create",{target:target},callback);
			},
			//取消关注
			clear:function(target,callback)
			{
				simplePost("/user/follow/delete",{target:target},callback);
			}
		},
		active:
		{
			//返回用户动态
			findByUser:function(id,pn,callback)
			{
				simpleGet("/user/active/user/"+id,{pn:pn},callback);
			}
		},
		mail:
		{
			//根据类型返回
			findByType:function(type,pn,callback)
			{
				simpleGet("/user/mail/token",{type:type,pn:pn},callback);
			},
			//返回未读
			getUnread:function(callback)
			{
				simpleGet("/user/mail/unread",{},callback);
			},
			//创建
			create:function(title,content,target,callback)
			{
				simplePost("/user/mail/create",{title:title,content:content,target:target},callback);
			},
			//设置已读
			setRead:function(id,callback)
			{
				simplePost("/user/mail/read/"+id,{},callback);
			},
			//删除
			remove:function(id,callback)
			{
				simplePost("/user/mail/delete/"+id,{},callback);
			},
			type:
			{
				//返回类型
				find:function(callback)
				{
					simpleGet("/user/mail/type",{},callback);
				}
			}
		}
	};
	
	//动弹
	request.dongtan=
	{
		//根据ID返回
		findById:function(id,callback)
		{
			simpleGet("/dongtan/"+id,{},callback);
		},
		//最新动弹
		upToDate:function(pn,callback)
		{
			simpleGet("/dongtan/upToDate",{pn:pn},callback);
		},
		//最热动弹
		hot:function(pn,callback)
		{
			simpleGet("/dongtan/hot",{pn:pn},callback);
		},
		//创建动弹
		create:function(content,callback)
		{
			simplePost("/dongtan/create",{content:content},callback);
		},
		//编辑
		edit:function(id,content,callback)
		{
			simplePost("/dongtan/edit/"+id,{content:content},callback);
		},
		//删除
		remove:function(id,callback)
		{
			simplePost("/dongtan/delete/"+id,{},callback);
		},
		comment:
		{
			//创建评论
			create:function(id,content,quote,callback)
			{
				simplePost("/dongtan/comment/create",{id:id,content:content,quote:quote},callback);
			}
		}
	};
	
	//评论
	request.comment=
	{
		//编辑
		edit:function(id,content,callback)
		{
			simplePost("/comment/edit/"+id,{content:content},callback);
		},
		//根据ID返回
		findByCommentId:function(id,pn,callback)
		{
			simpleGet("/comment/comments/"+id,{pn:pn},callback);
		},
		//删除
		remove:function(id,callback)
		{
			simplePost("/comment/delete/"+id,{},callback);
		},
		//返回引用
		findByQuote:function(id,pn,callback)
		{
			simpleGet("/comment/"+id+"/quote",{pn:pn},callback);
		},
		report:
		{
			//举报
			create:function(id,content,callback)
			{
				simplePost("/comment/report/"+id,{content:content},callback);
			}
		}
	};
	
	//api
	request.openApi=
	{
		//返回
		find:function(callback)
		{
			simpleGet("/openApi/",{},callback);
		}
	}
	
	//讨论
	request.discuss=
	{
		//搜索
		search:function(keyword,callback)
		{
			simpleGet("/discuss/search",{keyword:keyword},callback);
		},
		//根据软件返回
		findBySoftware:function(id,callback)
		{
			simpleGet("/discuss/software/"+id,{},callback);
		},
		//首页
		index:function(callback)
		{
			simpleGet("/discuss/index",{},callback);
		},
		//根据ID返回
		findById:function(id,callback)
		{
			simpleGet("/discuss/"+id,{},callback);
		},
		//根据板块返回
		findByForum:function(forum,pn,callback)
		{
			simpleGet("/discuss/forum/"+forum,{pn:pn},callback);
		},
		//创建
		create:function(title,content,forum,tags,callback)
		{
			simplePost("/discuss/create",{title:title,content:content,forum:forum,tags:tags},callback);
		},
		//编辑
		edit:function(id,title,content,callback)
		{
			simplePost("/discuss/edit/"+id,{title:title,content:content},callback);
		},
		//移动板块
		moveForum:function(id,forumId,callback)
		{
			simplePost("/discuss/moveForum",{id:id,forum:forumId},callback);
		},
		//删除
		remove:function(id,callback)
		{
			simplePost("/discuss/delete/"+id,{},callback);
		},
		//更新排序
		updateOrder:function(id,order,callback)
		{
			simplePost("/discuss/update/order/"+id,{order:order},callback);
		},
		comment:
		{
			//创建评论
			create:function(id,content,quote,callback)
			{
				simplePost("/discuss/comment/create",{id:id,content:content,quote:quote},callback);
			}
		},
		//板块
		forum:
		{
			//返回
			find:function(callback)
			{
				simpleGet("/discuss/forum/",{},callback);
			},
			//返回标签
			findTag:function(forum,callback)
			{
				simpleGet("/discuss/forum/tag/"+forum,{},callback);
			}
		},
		order:
		{
			//返回
			find:function(callback)
			{
				simpleGet("/discuss/order/",{},callback);
			}
		},
		favorite:
		{
			//关注
			create:function(id,callback)
			{
				simplePost("/discuss/favorite/create",{id:id},callback);
			},
			//删除关注
			remove:function(id,callback)
			{
				simplePost("/discuss/favorite/delete",{id:id},callback);
			}
		},
		report:
		{
			//举报
			create:function(id,content,callback)
			{
				simplePost("/discuss/report/"+id,{content:content},callback);
			}
		}
	};
	
	request.friendlink=
	{
		//返回
		find:function(callback)
		{
			simpleGet("/friendlink/",{},callback);
		}
	};
	
	request.blog=
	{
		//搜索
		search:function(keyword,callback)
		{
			simpleGet("/blog/search",{keyword:keyword},callback);
		},
		//根据作者返回最新
		findNewByAuthor:function(id,callback)
		{
			simpleGet("/blog/user/"+id+"/new",{},callback);
		},
		//根据作者返回
		findByAuthor:function(id,pn,callback)
		{
			simpleGet("/blog/user/"+id,{pn:pn},callback);
		},
		//根据作者和目录返回
		findByAuthorAndCatalog:function(id,catalog,pn,callback)
		{
			simpleGet("/blog/user/"+id+"/catalog/"+catalog,{pn:pn},callback);
		},
		//根据ID返回
		findById:function(id,callback)
		{
			simpleGet("/blog/"+id,{},callback);
		},
		//返回最新推荐
		findRecommend:function(pn,callback)
		{
			simpleGet("/blog/recommend",{pn:pn},callback);
		},
		//创建
		create:function(title,content,order,catalog,comment,oneself,callback)
		{
			simplePost("/blog/create",{title:title,content:content,order:order,catalog:catalog,comment:comment,oneself:oneself},callback);
		},
		//编辑
		edit:function(id,title,content,order,catalog,comment,oneself,callback)
		{
			simplePost("/blog/edit/"+id,{title:title,content:content,order:order,catalog:catalog,comment:comment,oneself:oneself},callback);
		},
		//删除
		remove:function(id,callback)
		{
			simplePost("/blog/delete/"+id,{},callback);
		},
		//设置/取消推荐
		setRecommend:function(id,callback)
		{
			simplePost("/blog/setRecommend/"+id,{},callback);
		},
		comment:
		{
			//创建评论
			create:function(id,content,quote,callback)
			{
				simplePost("/blog/comment/create",{id:id,content:content,quote:quote},callback);
			}
		},
		order:
		{
			//返回排序
			find:function(callback)
			{
				simpleGet("/blog/order/",{},callback);
			}
		},
		catalog:
		{
			//返回当前用户的目录
			find:function(callback)
			{
				simpleGet("/blog/catalog/token",{},callback);
			},
			//创建
			create:function(name,callback)
			{
				simplePost("/blog/catalog/create",{name:name},callback);
			},
			//更新
			update:function(id,name,callback)
			{
				simplePost("/blog/catalog/update/"+id,{name:name},callback);
			},
			//删除
			remove:function(id,target,callback)
			{
				simplePost("/blog/catalog/delete/"+id,{target:target},callback);
			},
			//根据用户返回
			findByUser:function(id,callback)
			{
				simpleGet("/blog/catalog/user",{id:id},callback);
			}
		},
		favorite:
		{
			//关注
			create:function(id,callback)
			{
				simplePost("/blog/favorite/create",{id:id},callback);
			},
			//删除关注
			remove:function(id,callback)
			{
				simplePost("/blog/favorite/delete",{id:id},callback);
			}
		},
		recommend:
		{
			//自荐
			create:function(id,callback)
			{
				simplePost("/blog/recommend/create",{id:id},callback);
			}
		}
	};
	
	request.favorite=
	{
		//根据类型返回
		findByType:function(type,pn,callback)
		{
			simpleGet("/favorite/"+type,{pn:pn},callback);
		},
		type:
		{
			//返回
			find:function(callback)
			{
				simpleGet("/favorite/type/",{},callback);
			}
		}
	};
	
	return request;
});